<?php
namespace app\admin\model;

use think\Model;

use app\admin\model\AuthGroupAccess;

class Admin extends Model
{   
    protected $pk = 'id';
    protected $autoWriteTimestamp = 'datetime';
    protected $createTime = 'created';
    protected $updateTime = 'updated';

    // 分配权限
    public function auth_group_access($role){
        AuthGroupAccess::where(['uid'=>$this->id])->delete();
        $role_data = [];
        foreach($role as $v){
            $role_data[] = [
                'uid'      => $this->id,
                'group_id' => $v
            ];
        }
        (new AuthGroupAccess)->saveAll($role_data);
    }

}